import React from "react"

import { IlabelDictRes } from "@/components/business/memberDetail/basicInfo/components/LabelMemberModal"
import { dataLimitedRedRes } from "@/components/business/memberDetail/limitedRed"

import http from "../helper/request"
import {
	IAdjustList,
	IBalanceInfo,
	IBatchInfoParams,
	IBatchQueryMemberLimitRedParams,
	IBmhMemberInfoEdit,
	ICreditLevelParams,
	ICreditListParams,
	IDataBet,
	IFlowAdjustParams,
	IGetUserBankList,
	IMemberInfoEdit,
	IMemberList,
	IMemberLoginList,
	IMemberRiskControlNoteParams,
	IMemberSaveRiskControlNoteParams,
	IQueryBasicInfoParams,
	IQueryClubContributeListParams,
	IQueryMemberListParams,
	IQuerymemberLoginLogParams,
	IQueryMemberLoginParams,
	IQueryPlayerTop3Params,
	ISelectWindControlLevelParams,
	ITeamlateListParams,
	ITeamlateListRes,
	ITeamlateUpdateBatchParams,
	IUserInfo,
	IWindControlLevelNameRes
} from "./types"

export const queryBasicInfo = (params: IQueryBasicInfoParams) => http.get<IUserInfo>("/member/outlineInfo", params)
export const queryMemberInfoEdit = (params: IMemberInfoEdit) => http.post<any>("/member/infoEdit", params)
export const queryRebateStatusEdit = (params: IMemberInfoEdit) => http.post<any>("/rebateStatusFreezeRecord/saveOrUpdate", params)
export const querySetBmhMemberInfoEdit = (params: IBmhMemberInfoEdit) => http.post<any>("/member/unbindBmh", params)

export const queryGetRiskControlNote = (params: IMemberRiskControlNoteParams) =>
	http.post<any>("/risk-control-note/get-page-by-user-id", params)
export const querySaveRiskControlNote = (params: IMemberSaveRiskControlNoteParams) =>
	http.post<any>("/risk-control-note/save", params)

export const queryMemberLoginLog = (params: IQuerymemberLoginLogParams) => http.post<IMemberList>("/log/memberLoginLog", params)
export const queryClubContributeList = (params: IQueryClubContributeListParams) =>
	http.post<IMemberList>(
		"https://dxmerchant-fat.ak12.cc/dx-merchant-gateway/dx-game-data-manager/dxGameRecords/clubContributeList",
		params
	)
export const queryGetVerifyCodeType = () =>
	http.post<{ verifyCodeType: number }>("https://dxmerchant-fat.ak12.cc/dx-merchant-manager/dict/getVerifyCodeType")
export const queryFlowAdjust = (params: IFlowAdjustParams) =>
	http.post<any>("https://dxmerchant-fat.ak12.cc/dx-merchant-manager/member/detail/flow/adjust", params)

export const queryAdjustList = (params: IAdjustList) =>
	http.post<IMemberList>("https://dxmerchant-fat.ak12.cc/dx-merchant-manager/member/detail/flow/adjust/list", params)

export const queryLimitedRed = (params: IQuerymemberLoginLogParams) =>
	http.post<dataLimitedRedRes[]>("/venue/redLimit/getMemberVenueLimitRed", params)

export const queryTeamlateUpdateBatch = (params: ITeamlateUpdateBatchParams) =>
	http.post<dataLimitedRedRes[]>("/venue/redLimit/templateUpdateBatch", params)

export const queryBatchQueryMemberLimitRed = (params: IBatchQueryMemberLimitRedParams) =>
	http.post<ITeamlateUpdateBatchParams[]>("/venue/redLimit/batchQueryMemberLimitRed", params)

export const queryTeamlateList = (params: ITeamlateListParams) =>
	http.post<ITeamlateListRes[]>("/venue/redLimit/templateList", params)

export const queryBankCard = (params: IQuerymemberLoginLogParams) =>
	http.post<IGetUserBankList>("/member/detail/getUserCardInfo", params)
export const queryTableList = (params: IQuerymemberLoginLogParams) => http.post<IMemberList>("/dxtable/list", params)

export const queryPlayerTop3 = (params: IQueryPlayerTop3Params) => http.get<any>("/player/top3", params)
export const queryPlayerBetHistorySum = (params: IQueryPlayerTop3Params) =>
	http.post<IDataBet>("/member/playerBetHistorySum", params)

export const queryMemberBalance = (params: IQueryPlayerTop3Params) => http.post<IBalanceInfo>("/member/detail/balance", params)

export const queryMemberRemarkList = (params: IQueryPlayerTop3Params) => http.get<IMemberList>("/memberRemark/list", params)

export const querySelectWindControlLevel = (params: ISelectWindControlLevelParams) =>
	http.post<IWindControlLevelNameRes[]>("/windControllerLevel/selectWindControlLevel", params)
export const queryLabelDict = (params: IMemberInfoEdit) => http.post<IlabelDictRes[]>("/userLabel/labelDict", params)
export const queryPersonGetValue = (params: IMemberInfoEdit) => http.post<any>("/person/getValue", params)
export const queryMemberRemakeAdd = (params: IMemberInfoEdit) => http.post<any>("/memberRemark/add", params)

export const queryCreditLevelConf = (params: ICreditListParams) => http.post<any>("CreditLevelConf/creditList", params)

export const queryMemberListExport = (params: IQueryMemberListParams) =>
	http.post<Blob>("/member/memberLsExport", params, { responseType: "blob" })
export const queryBatchInfoEdit = (params: IBatchInfoParams) => http.post("/member/batchInfoEdit", params)
export const queryMemberLoginList = (params: IQueryMemberLoginParams) =>
	http.post<IMemberLoginList>("/log/memberLoginLog", params)

const useMemberApi = () => {
	const { useState } = React
	const [loading, setLoading] = useState(false)

	async function generalHttp<T>(url: string, body: object | undefined) {
		setLoading(true)
		const ret = await http.post<T>(url, body)
		setLoading(false)
		return ret
	}

	const queryMemberList = async (params: IQueryMemberListParams) => {
		const ret = await generalHttp<IMemberList>("/member/queryMemberLs", params)
		return ret
	}

	const queryCreditLevelList = async (params: ICreditLevelParams) => {
		const ret = await generalHttp<number[]>("/CreditLevelConf/creditList", params)
		return ret
	}

	const memberTransAgentAPI = async (params: any) => await generalHttp("/memberTransfer/apply", params)

	return {
		queryMemberList,
		generalHttp,
		queryCreditLevelList,
		memberTransAgentAPI,
		queryRebateStatusEdit,
		querySetBmhMemberInfoEdit,
		loading
	}
}

export default useMemberApi
